using System;
using System.Windows;
using System.Xml.Serialization;
using MaxAlarm.Common;

namespace MaxAlarm.Core.Settings
{
    [XmlType("settings")]
    public class MaxAlarmSettings : DependencyObject, ICloneable
    {
        #region AutoRefreshInterval

        public static readonly DependencyProperty AutoRefreshIntervalProperty =
            DependencyProperty.Register("AutoRefreshInterval", typeof (int), typeof (MaxAlarmSettings), new PropertyMetadata(10));

        [XmlElement("refresh-interval")]
        public int AutoRefreshInterval
        {
            get { return (int) GetValue(AutoRefreshIntervalProperty); }
            set { this.SafeSetValue(AutoRefreshIntervalProperty, value); }
        }

        #endregion

        #region Base Address

        public static readonly DependencyProperty BaseAddressProperty =
            DependencyProperty.Register("BaseAddress", typeof (string), typeof (MaxAlarmSettings), new PropertyMetadata("127.0.0.1"));

        [XmlElement("base-address")]
        public string BaseAddress
        {
            get { return this.SafeGetValue<string>(BaseAddressProperty); }
            set { this.SafeSetValue(BaseAddressProperty, value); }
        }


        #endregion

        #region Startup filters

        public static readonly DependencyProperty StartupFiltersProperty =
            DependencyProperty.Register("StartupFilters", typeof (string), typeof (MaxAlarmSettings), new PropertyMetadata("kh"));

        [XmlElement("startup-filters")]
        public string StartupFilters
        {
            get { return this.SafeGetValue<string>(StartupFiltersProperty); }
            set { this.SafeSetValue(StartupFiltersProperty, value); }
        }

        #endregion

        #region Alert settings

        public static readonly DependencyProperty AlertSettingsProperty =
            DependencyProperty.Register("AlertSettings", typeof (AlertSettings), typeof (MaxAlarmSettings), new PropertyMetadata(null));

        [XmlElement("alert-settings")]
        public AlertSettings AlertSettings
        {
            get { return this.SafeGetValue<AlertSettings>(AlertSettingsProperty); }
            set { this.SafeSetValue(AlertSettingsProperty, value); }
        }

        #endregion

        #region Accounts

        public static readonly DependencyProperty AccountsSettingsProperty =
            DependencyProperty.Register("AccountsSettings", typeof(AccountsSettings), typeof(MaxAlarmSettings), new PropertyMetadata(null));

        [XmlElement("accounts-settings")]
        public AccountsSettings AccountsSettings
        {
            get { return this.SafeGetValue<AccountsSettings>(AccountsSettingsProperty); }
            set { this.SafeSetValue(AccountsSettingsProperty, value); }
        }

        #endregion

        #region Alarms

        public static readonly DependencyProperty AlarmSettingsProperty =
            DependencyProperty.Register("AlarmSettings", typeof(AlarmSettings), typeof(MaxAlarmSettings), new PropertyMetadata(null));

        [XmlElement("alarms-settings")]
        public AlarmSettings AlarmSettings
        {
            get { return this.SafeGetValue<AlarmSettings>(AlarmSettingsProperty); }
            set { this.SafeSetValue(AlarmSettingsProperty, value); }
        }


        #endregion

        public object Clone()
        {
            return new MaxAlarmSettings
                       {
                           AutoRefreshInterval = AutoRefreshInterval,
                           BaseAddress = BaseAddress,
                           StartupFilters = StartupFilters,
                           AccountsSettings = (AccountsSettings)AccountsSettings.Clone(),
                           AlarmSettings = (AlarmSettings)AlarmSettings.Clone(),
                           AlertSettings = (AlertSettings)AlertSettings.Clone()
                       };
        }
    }
}